package com.gitee.ly;

import org.noear.solon.cloud.CloudDiscoveryHandler;
import org.noear.solon.cloud.model.Discovery;
import org.noear.solon.cloud.model.Instance;
import org.noear.solon.cloud.service.CloudDiscoveryService;
import org.noear.solon.core.AppContext;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class CloudDiscoveryServiceLightRegistryImpl implements CloudDiscoveryService {
    private Map<String, DynamicDiscover> dynamicDiscoverCacheMap = new ConcurrentHashMap<>();
    private AppContext appContext;

    public CloudDiscoveryServiceLightRegistryImpl(AppContext context) {
        this.appContext = context;
    }

    @Override
    public void register(String group, Instance instance) {
    }

    @Override
    public void registerState(String group, Instance instance, boolean health) {
    }

    @Override
    public void deregister(String group, Instance instance) {
    }

    @Override
    public Discovery find(String group, String service) {
        return dynamicDiscoverCacheMap.computeIfAbsent(service, (String serviceName) -> new DynamicDiscover(group, serviceName, this.appContext));
    }

    @Override
    public Collection<String> findServices(String group) {
        return new ArrayList<>();
    }

    @Override
    public void attention(String group, String service, CloudDiscoveryHandler observer) {
    }
}
